import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
const store = new Vuex.Store({
  state: {
    username: 'shen yukun',
    blogs: [
      {
        name: 'how hard it could be',
        date1: '2019-10-23',
        date2: '2019-10-23 12：00',
        type: ['JavaScript'],
        resource: '转载',
        desc: 'cross'
      }
    ]
  },
  getters: {
    westname: state => {
      return state.username.split(' ').reverse().join()
    },
    manageBlogs: state => {
      return state.blogs.map(function (item) {
        item.date1 = item.date2.toString().split(' GMT')[0]
        return item
      })
    }
  },
  mutations: {
    submit: (state, data) => {
      state.blogs.unshift(data)
    },
    delete: (state, index) => {
      state.blogs.splice(index, 1)
    }
  },
  actions: {
    //
  }
})

export default store
